<?php
/***************************************************************
*  Copyright notice
*  (c) 2009, jianyuzhu@gmail.com
*  All rights reserved
*  This script is part of the PPEMI project.
***************************************************************/

//
include(CONFIG_PATH . 'lib/xajax_0.2.4/xajax.inc.php');

///////////////////////////////////////////////////////////////////////////////
//
function _alert_auth() {
	$objResponse = new xajaxResponse();
	$msg = "You dont have permission!";
	$objResponse->addAlert($msg);
	
	return $objResponse;
}

function _alert_message($msg) {
	$objResponse = new xajaxResponse();
	$objResponse->addAlert($msg);
	
	return $objResponse;
}

function _script_cb($call, $result) {
	$objResponse = new xajaxResponse();
	$objResponse->addScriptCall($call, $result);
	
	return $objResponse;
}

function _check_auth($type = 'admin') {
	if( $type == 'admin' ) {
		if( $_SESSION['suser']->userid > 0 && $_SESSION['suser']->usertype == 'admin' ) {
			return true;
		}
	} elseif( $type == 'member' ) {
		if( $_SESSION['suser']->userid > 0 && in_array($_SESSION['suser']->usertype, array('member', 'admin')) ) {
			return true;
		}
	} else {
		if( $_SESSION['suser']->userid == 0 ) {
			return true;
		}
	}
	
	return false;
}

///////////////////////////////////////////////////////////////////////////////
//
define('SYS_RT_FRONT_TYPE', str_replace('.front.php', '', basename(__FILE__)));
define('SYS_RT_FRONT_PATH', CONFIG_PATH . CONFIG_DIR_FRONTS . SYS_RT_FRONT_TYPE . '/');

//
if( $request_link_class ) {
	switch($request_link_class) {
	//---------------------------------------------------------------------------//
		case 'home':
			include_once(SYS_RT_FRONT_PATH . 'home.' . SYS_RT_FRONT_TYPE . '.front.php');
			break;
	//---------------------------------------------------------------------------//
		default:
			if( util_file_exists(SYS_RT_FRONT_PATH, $request_link_class, '.' . SYS_RT_FRONT_TYPE . '.front.php') ) {
				include_once(SYS_RT_FRONT_PATH . $request_link_class . '.' . SYS_RT_FRONT_TYPE . '.front.php');
			} else {
				include_once(SYS_RT_FRONT_PATH . 'home.' . SYS_RT_FRONT_TYPE . '.front.php');
			}
			break;
	}
} else {
	include_once(SYS_RT_FRONT_PATH . 'home.' . SYS_RT_FRONT_TYPE . '.front.php');
}
//
?>